'use strict';
const Service = require('egg').Service;

class RegisterController extends Service {
  async register (data) {
    const { ctx } = this;
    console.log('客户端用户注册：', data);
    const isable = await this.app.mysql.select('users', {
      where: {
        username: data.username,
      },
    });
    console.log('xxx:', isable.length);
    if (isable.length === 0) {
      delete data.checkPassword;
      await this.app.mysql.insert('users', data);
      return {
        code: 200,
        message: `${data.username}用户注册成功`,
      };
    }
    return false;
  }
  async userup (data) {
    console.log('企业认证：', data);
    // const imglist = [];
    // for (let i = 0; i < data.company_user_idimg.length; i++) {
    //   imglist.push(data.company_user_idimg[i].url);
    // }
    // const idimg = imglist.toString()

    // console.log('urllist:', imglist.toString());
    // const sqldata = [data.company_address, data.company_email, data.company_fax, data.company_finance_user, data.company_idimg,
    // data.company_idnumber, data.company_iphone, data.company_name, data.company_user, data.company_user_id, imglist.toString(),
    // data.company_user_iphone, data.users_id];
    // // update 表名 set 字段名1=值1,字段名2=值2,... where 条件;
    // const sql = 'update users set company_address=?, company_email=?, company_fax=?, company_finance_user=?, company_idimg=?, ' +
    //   'company_idnumber=?, company_iphone=?, company_name=?, company_user=?, company_user_id=?, company_user_idimg=?, company_user_iphone=? where users_id=?';
    const options = {
      where: {
        users_id: data.users_id,
      },
    };
    const res = await this.app.mysql.update('users', data, options);
    return res;
    // const res = await this.app.mysql.query(sql, sqldata);
    // return res;
  }
}
module.exports = RegisterController;
